class Solution:
    def indexInAlphabet(self, s: str) -> int:
        """
        :type s: str
        :rtype: int
        """
        return ord(s) - ord('a') + 1
    def distance(self,s1,s2):
        ans = 0
        for i in range(len(s1)):
            abs_dis = abs(self.indexInAlphabet(s1[i]) - self.indexInAlphabet(s2[i]))
            ans += min(26-abs_dis,abs_dis)
        return ans
    def getSmallestString(self, s: str, k: int) -> str:
        """
        :type s: str
        :type k: int
        :rtype: str
        """
        lst_s = list(s)
        n = len(s)
        i = 0
        while i<n and k>0:
            if self.distance(s[i],'a') <= k:
                lst_s[i] = 'a'
                k -= self.distance(s[i],'a')
            else:
                lst_s[i] = chr(ord(s[i]) - k)
                k = 0
            i += 1
        return ''.join(lst_s)